"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SocketClientMsgHandler = void 0;
const RoomModel_1 = require("../../../../hall_server/model/RoomModel");
const RoomTemplateModel_1 = require("../../../../hall_server/model/RoomTemplateModel");
const Config_1 = require("../../../config/Config");
const ServerConfig_1 = require("../../../config/ServerConfig");
const jhaoproto_1 = require("../../../lib/net/protobuf/jhaoproto");
const ProtoManager_1 = require("../../../lib/net/protobuf/ProtoManager");
const Logger_1 = require("../../utils/Logger");
const SocketConnectionManager_1 = require("./SocketConnectionManager");
class SocketClientMsgHandler {
    static onEventSocketGata(socketConnect, msg) {
        Logger_1.Logger.log("SocketClientMsgHandler======", socketConnect.isLogin(), msg);
        if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_Login) {
            this.server_internal_Login(socketConnect, msg);
        }
        else if (socketConnect.isLogin()) {
            if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_kill_all_users) {
                this.server_internal_kill_all_users(socketConnect, msg);
            }
            else if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_set_server_status) {
                this.server_internal_set_server_status(socketConnect, msg);
            }
            else if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_get_server_status) {
                this.server_internal_get_server_status(socketConnect, msg);
            }
            else if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_update_online) {
                this.server_internal_update_online(socketConnect, msg);
            }
            else if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_is_in_server) {
                this.server_internal_is_in_server(socketConnect, msg);
            }
            else if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_club_create_room_template) {
                this.server_internal_club_create_room_template(socketConnect, msg);
            }
            else if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_club_delete_room_template) {
                this.server_internal_club_delete_room_template(socketConnect, msg);
            }
            else if (msg.cmdIndex == jhaoproto_1.JhaoProto.CmdIndex.server_internal_createRoom) {
                this.server_internal_createRoom(socketConnect, msg);
            }
        }
        else {
            socketConnect.sendErrorToClient(0, jhaoproto_1.JhaoProto.ErrorCodeWs.LoginError_NoLogin, "账号未登录");
        }
        // else if (msg.protoName == ProtoServerConfig.req_server_onlie_club) {
        //     this.on_req_server_onlie_club(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_delete_club_user) {
        //     this.on_req_server_notify_delete_club_user(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_set_club_quanxian) {
        //     this.req_server_notify_set_club_quanxian(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_club_freeze) {
        //     this.req_server_notify_club_freeze(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_set_club_admin) {
        //     this.req_server_notify_set_club_admin(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_joinRoom) {
        //     this.on_req_server_joinRoom(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_deleteRoom) {
        //     this.on_req_server_deleteRoom(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_leave_room) {
        //     this.on_req_server_leave_room(socketConnect, msg);
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_game_start) {
        //     this.on_req_server_notify_game_start(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_update_gems) {
        //     this.req_server_notify_update_gems(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_update_coins) {
        //     this.req_server_notify_update_coins(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_update_income) {
        //     this.req_server_notify_update_income(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_update_meili) {
        //     this.req_server_notify_update_meili(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_update_lv) {
        //     this.req_server_notify_update_lv(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_update_invite) {
        //     this.req_server_notify_update_invite(socketConnect, msg)
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_update_img) {
        //     this.req_server_notify_update_img(socketConnect, msg);
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_notify_club_open_or_close) {
        //     this.req_server_notify_club_open_or_close(socketConnect, msg);
        // }
        // else if (msg.protoName == ProtoServerConfig.req_server_delete_room_by_hall) {
        //     this.req_server_delete_room_by_hall(socketConnect, msg)
        // }
    }
    static server_internal_Login(conn, socketMsg) {
        let protoPack = ProtoManager_1.ProtoManager.instance.decode(jhaoproto_1.JhaoProto.req_server_internal_Login, socketMsg.data);
        if (protoPack.pass != "sjh666666") {
            conn.sendErrorToClient(0, jhaoproto_1.JhaoProto.ErrorCodeWs.LoginError_NoPass, "密码错误");
            conn.gotoClose();
        }
        else {
            for (const key in Config_1.Config.ServerType_List) {
                let value = Config_1.Config.ServerType_List[key];
                if (protoPack.account.includes(value)) {
                    conn.isInternalServer = true;
                    conn.account = protoPack.account;
                    conn.sendErrorToClient(socketMsg.cmdOrder, jhaoproto_1.JhaoProto.ErrorCodeWs.Suc, "", socketMsg.cmdIndex);
                    break;
                }
            }
        }
    }
    static server_internal_kill_all_users(conn, socketMsg) {
        SocketConnectionManager_1.SocketConnectionManager.instance.killAllByWeihu();
    }
    static server_internal_set_server_status(conn, socketMsg) {
        let protoPack = ProtoManager_1.ProtoManager.instance.decode(jhaoproto_1.JhaoProto.req_server_internal_set_server_status, socketMsg.data);
        ServerConfig_1.ServerConfig.nowServerConfig.status = protoPack.status;
    }
    static server_internal_get_server_status(conn, socketMsg) {
        let respData = {
            status: ServerConfig_1.ServerConfig.nowServerConfig.status
        };
        Logger_1.Logger.log("server_internal_get_server_status", respData);
        conn.createMsgToClient(socketMsg.cmdIndex, socketMsg.cmdOrder, jhaoproto_1.JhaoProto.resp_server_internal_get_server_status, respData);
    }
    static server_internal_update_online(conn, socketMsg) {
        let protoPack = ProtoManager_1.ProtoManager.instance.decode(jhaoproto_1.JhaoProto.req_server_internal_update_online, socketMsg.data);
        ServerConfig_1.ServerConfig.update_online(protoPack.serverId, protoPack.serverType, protoPack.userids);
    }
    static server_internal_is_in_server(conn, socketMsg) {
        let protoPack = ProtoManager_1.ProtoManager.instance.decode(jhaoproto_1.JhaoProto.req_server_internal_is_in_server, socketMsg.data);
        let isIn = false;
        if (protoPack.account && protoPack.account != "") {
            SocketConnectionManager_1.SocketConnectionManager.instance.socketConnMap.forEach((conn, key) => {
                if (conn.isLogin()) {
                    if (conn.account == protoPack.account) {
                        isIn = true;
                        return;
                    }
                }
            });
        }
        let respData = {
            isIn: isIn
        };
        conn.createMsgToClient(socketMsg.cmdIndex, socketMsg.cmdOrder, jhaoproto_1.JhaoProto.resp_server_internal_is_in_server, respData);
    }
    static server_internal_club_create_room_template(conn, socketMsg) {
        RoomTemplateModel_1.RoomTemplateModel.init();
    }
    static server_internal_club_delete_room_template(conn, socketMsg) {
        let protoPack = ProtoManager_1.ProtoManager.instance.decode(jhaoproto_1.JhaoProto.req_server_internal_club_delete_room_template, socketMsg.data);
        RoomTemplateModel_1.RoomTemplateModel.deleteRoomTemplate(protoPack.id);
    }
    static server_internal_createRoom(conn, socketMsg) {
        let protoPack = ProtoManager_1.ProtoManager.instance.decode(jhaoproto_1.JhaoProto.req_server_internal_createRoom, socketMsg.data);
        RoomModel_1.RoomModel.roomMap.set(protoPack.room.roomId, protoPack.room);
        let protoResp = {};
        conn.createMsgToClient(socketMsg.cmdIndex, socketMsg.cmdOrder, jhaoproto_1.JhaoProto.resp_server_internal_createRoom, protoResp);
    }
}
exports.SocketClientMsgHandler = SocketClientMsgHandler;
